package name.wilbur.course.db.bigone.ui;

import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public abstract class BaseWindow implements IWindow {
	protected Display disp;
	protected Shell sShell;
	
	protected BaseWindow() {
		disp = new Display();
	}
	
	protected BaseWindow(Display disp) {
		this.disp = disp;
	}
	
	public void close() {
		sShell.close();
	}
	
	public void open() {
		createSShell();
		initWindowData();
		sShell.addDisposeListener(new DisposeListener () {
			public void widgetDisposed(DisposeEvent e) {
		    	   doBeforeDispose();
		    	   close();
		    	   doAfterDispose();
			}
		});
//		sShell.pack();
		sShell.open();
		updateWindowData();
		
		while (!sShell.isDisposed()) {
			if (!disp.readAndDispatch()) {
				disp.sleep();
			}
		}
	}
	
	public void initWindowData() {
	}
	public void updateWindowData() {
	}
	
	public void doBeforeDispose() {
	}
	public void doAfterDispose() {
	}
	
	public void quit() {
		disp.dispose();
	}
	
	public abstract void createSShell();
	
	public Display getDisplay() {
		return disp;
	}
	
	public void setDisplay(Display disp) {
		this.disp = disp;
	}
	
	public Shell getShell() {
		return sShell;
	}
	
	public void setShell(Shell sShell) {
		this.sShell = sShell;
	}
}
